﻿using LyData.Data.Xml;
using System;
using System.Data;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_MenuConfig : System.Web.UI.Page
{
    protected void Bind()
    {
        string str = SiteInfo.SiteLanguage();
        DataRow row = new XmlProvider(base.Server.MapPath("~/App_Data/MenuConfig.xml")).ReadNode(string.Format("descendant::MenuConfig[Language='{0}']", str));
        if (row != null)
        {
            this.ArticlePageSize.Text = (string)row["ArticlePageSize"];
            this.ArticleDateTimeFormat.Text = (string)row["ArticleDateTimeFormat"];
            this.PicRowNum.Text = (string)row["PicRowNum"];
            this.PicColumnsNum.Text = (string)row["PicColumnsNum"];
            this.PicListWidth.Text = (string)row["PicListWidth"];
            this.PicListHeight.Text = (string)row["PicListHeight"];
            this.PicListTitleLength.Text = (string)row["PicListTitleLength"];
            this.PicListShortContentLength.Text = (string)row["PicListShortContentLength"];
            this.PicDetailWidth.Text = (string)row["PicDetailWidth"];
            this.PicDetailHeight.Text = (string)row["PicDetailHeight"];
            this.ProductRowNum.Text = (string)row["ProductRowNum"];
            this.ProductColumnsNum.Text = (string)row["ProductColumnsNum"];
            this.ProductListWidth.Text = (string)row["ProductListWidth"];
            this.ProductListHeight.Text = (string)row["ProductListHeight"];
            this.ProductListTitleLength.Text = (string)row["ProductListTitleLength"];
            this.ProductListShortContentLength.Text = (string)row["ProductListShortContentLength"];
            this.ProductDetailWidth.Text = (string)row["ProductDetailWidth"];
            this.ProductDetailHeight.Text = (string)row["ProductDetailHeight"];
            this.MoneyUnit.Text = (string)row["MoneyUnit"];
            this.MessageRowNum.Text = (string)row["MessageRowNum"];
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Msg.Visible = false;
        if (!ManagerLogin.ValidateRole("B_MenuConfig.aspx"))
        {
            this.Msg.CssClass = "errorMsg";
            this.Msg.Text = "您无此权限！";
            this.Msg.Visible = true;
            this.Save.Enabled = false;
        }
        else if (!base.IsPostBack)
        {
            this.Bind();
        }
    }

    protected void Save_Click(object sender, EventArgs e)
    {
        string str = SiteInfo.SiteLanguage();
        XmlProvider provider = new XmlProvider(base.Server.MapPath("~/App_Data/MenuConfig.xml"));
        string[,] nodeDateList = new string[,] { 
            { "Language", str }, { "ArticlePageSize", this.ArticlePageSize.Text }, { "ArticleDateTimeFormat", this.ArticleDateTimeFormat.Text }, { "PicRowNum", this.PicRowNum.Text }, { "PicColumnsNum", this.PicColumnsNum.Text }, { "PicListWidth", this.PicListWidth.Text }, { "PicListHeight", this.PicListHeight.Text }, { "PicListTitleLength", this.PicListTitleLength.Text }, { "PicListShortContentLength", this.PicListShortContentLength.Text }, { "PicDetailWidth", this.PicDetailWidth.Text }, { "PicDetailHeight", this.PicDetailHeight.Text }, { "ProductRowNum", this.ProductRowNum.Text }, { "ProductColumnsNum", this.ProductColumnsNum.Text }, { "ProductListWidth", this.ProductListWidth.Text }, { "ProductListHeight", this.ProductListHeight.Text }, { "ProductListTitleLength", this.ProductListTitleLength.Text }, 
            { "ProductListShortContentLength", this.ProductListShortContentLength.Text }, { "ProductDetailWidth", this.ProductDetailWidth.Text }, { "ProductDetailHeight", this.ProductDetailHeight.Text }, { "MoneyUnit", this.MoneyUnit.Text }, { "MessageRowNum", this.MessageRowNum.Text }
         };
        if (!provider.ValidateNode(string.Format("descendant::MenuConfig[Language='{0}']", str)))
        {
            provider.CreateNode("Doc", "MenuConfig", nodeDateList);
        }
        else
        {
            provider.ChangeNode(string.Format("descendant::MenuConfig[Language='{0}']", str), nodeDateList);
        }
        this.Msg.Text = "栏目配置更新成功！";
        this.Msg.Visible = true;
    }
}
